extends Panel


@onready var trophy_card := $TrophyCard
@onready var card_button = $Menu/CardButton
@onready var potion_button = $Menu/PotionButton
@onready var prop_button = $Menu/PropButton
@onready var skip_button = $Menu/SkipButton

var card_pressed = false
var potion_pressed = false
var prot_pressed = false

func _ready():
	Events.battle_win.connect(_on_battle_win)
	Events.trophy_select.connect(_on_trophy_select)

func _on_card_button_pressed():
	trophy_card.visible = true
	card_pressed = true
	card_button.disabled = true
	potion_button.disabled = true
	prop_button.disabled = true
	skip_button.disabled = true


func _on_trophy_select():
	trophy_card.visible = false
	if !card_pressed:
		card_button.disabled = false
	if !potion_pressed:
		potion_button.disabled = false
	if !prot_pressed:
		prop_button.disabled = false
	skip_button.disabled = false
	
func _on_battle_win():
	visible = true

func _on_skip_button_pressed():
	visible = false
	get_tree().paused = false
	CardManager.end_battle()
	get_tree().root.add_child(Globals.main_secne)
	var battle_main = get_tree().root.get_node("BattleMain")
	if battle_main != null:
		get_tree().root.remove_child(battle_main)
		battle_main.queue_free()
	Events.goback_main_map.emit()
	
